/**
* Calculates the difference between the current date and an end date in 
* days, hours, minutes and seconds. 
* @author Jeremy Wischusen - jwischusen@myyearbook.com
* @version 0.1
* 
*/

package com.myyearbook.timers {
	
	public class CountDown{
		private var countDownTo:Date;
		private var _days:Number
		private var _hours:Number
		private var _minutes:Number
		private var _seconds:Number
		/**
		 * Constructor. 
		 * @param	countDownTo:Date - The end date of the countdown. 
		 */
		public function CountDown(countDownTo:Date) {
			this.countDownTo = countDownTo;
		}
		/**
		 * When called, updates the instance variables to represent the 
		 * current number of days, hours, minutes and seconds left between 
		 * the current date and the target end date. 
		 */
		public function getCountDown() {
						
			var currentDate:Date = new Date();
			var timeLeft:Number = (this.countDownTo.getTime() - currentDate.getTime());
			var seconds:Number = Math.abs( Math.floor(timeLeft/1000));
			var minutes:Number = Math.floor(seconds/60);
			var hours:Number = Math.floor(minutes / 60);
			var days:Number = Math.floor(hours / 24);
			this._seconds = seconds % 60; 
			this._minutes = minutes % 60; 
			this._hours = hours % 24; 
			this._days = days; 
			trace("days " +this._days+  " hours " +this._hours+  " Minutes " +this._minutes+ " Seconds " + this._seconds)
		}
		/**
		 * Getter method for seconds. 
		 */
		public function get seconds() {
			return this._seconds; 
		}
		/**
		 * Getter method for minutes. 
		 */
		public function get minutes () {
			return this._minutes; 
		}
		/**
		 * Getter method for hours. 
		 */
		public function get hours() {
			return this._hours; 
		}
		/**
		 * Getter method for days. 
		 */
		public function get days() {
			return this._days; 
		}
	
		
	}
	
}
